package com.eric.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.bean.BeanUtil;
import com.eric.domain.bso.RoleBso;
import com.eric.domain.dto.SysRoleDto;
import com.eric.domain.po.SysRole;
import com.eric.service.ISysRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-03-12
 */
@RestController
@RequestMapping("/sys-role")
@RequiredArgsConstructor
public class SysRoleController {
    private final ISysRoleService sysRoleService;
//    批量增加角色
    @PostMapping("/saveRoleList")
    @SaCheckRole(value = {"coder"},mode = SaMode.OR)
    public SaResult saveRoleList(@RequestBody List<SysRoleDto>roleDtoList){
        return sysRoleService.saveRoleListService(roleDtoList);
    }
//    获取到所有角色列表
    @GetMapping("/getAllRoles")
    public SaResult getAllRolesService(Integer current,Integer pageSize){
        return sysRoleService.getAllRolesService(current,pageSize);
    }

//    删除Role角色
    @DeleteMapping("/deleteRoles")
    @SaCheckPermission("sys:delete")
    @SaCheckRole(value = {"coder"},mode = SaMode.OR)
    public SaResult deleteRoles(@RequestBody List<Integer> ids){
        return sysRoleService.deleteRolesService(ids);
    }


//  更改角色
    @PutMapping("/modifyRoles")
    @SaCheckRole(value = {"coder"},mode = SaMode.OR)
    @SaCheckPermission("sys:modify")
    public SaResult modifyRoles(@RequestBody List<SysRoleDto> roleDtos){
        return sysRoleService.modifyRolesService(roleDtos);
        }
//  根据id查询一条role
    @GetMapping("{id}")
    public SaResult getOneById(@PathVariable("id") Integer id){
        return sysRoleService.getOneByIdService(id);
    }
//  获取所有的角色列表
    @GetMapping("/getAll")
    public SaResult getAllRoles(){
        List<SysRole> list = sysRoleService.list();
        List<RoleBso> roleBsoList = BeanUtil.copyToList(list, RoleBso.class);
        return SaResult.data(roleBsoList);
    }

}
